package com.bjpowernode.shop.base;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.List;
import java.util.stream.Collectors;

public class Base {

    public String getStringUserId() {
        return SecurityContextHolder.getContext().getAuthentication().getName();
    }

    public Long getLongUserId() {
        return Long.valueOf(getStringUserId());
    }

    //获取用户权限列表
    public List<String> getAuthorities(){
        return SecurityContextHolder.getContext().getAuthentication().getAuthorities()
                .stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
    }
}
